package com.javaee.xiangyang.mapper;

import com.javaee.xiangyang.entity.ShopCar;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface ShopCarMapper {

    /**
     * 新建购物车
     */
//    @Insert("insert into shopcar values(#{shopId}, #{shopNumber}, #{shopTotal}, #{shopUserAccount}, #{shopGoodsId})")
    void insertShopCar(ShopCar shopCar);

    /**
     * 根据购物车Id查找具体信息
     */
//    @Select("select * from shopcar where shopId = #{shopId}")
    ShopCar findCarById(ShopCar shopCar);

    /**
     * 根据用户查找购物车内商品
     */
//    @Select("select * from shopcar where shopUserAccount = #{shopUserAccount}")
    List<ShopCar> findCarByUserAccount(ShopCar shopCar);

    /**
     * 根据用户ID加商品ID获取具体某一条购物车数据
     * 此方法该概率呗废除  暂时保留
     * 2021/6/23 不废除  保留用于判定购物车是否有此信息
     */
//    @Select("select * from shopcar where shopUserAccount = #{shopUserAccount} and shopGoodsId = #{shopGoodsId}")
    ShopCar findCarByAccountAndId(ShopCar shopCar);

    /**
     * 更新购物车内商品数量
     */
/*    @Update("update shopcar set shopNumber = #{shopNumber}, " +
            "shopTotal = #{shopNumber} * ( select goodsPrice from goods where goodsId = #{shopGoodsId} ) where " +
            "shopId = #{shopId}")*/
    void updateCarNumberBy(ShopCar shopCar);

    /**
     * 删除购物车一条信息
     */
//    @Delete("delete from shopcar where shopId = #{shopId}")
    void deleteCarByUserAccountAndGoodsId(ShopCar shopCar);

    /**
     * 清空购物车
     */
//    @Delete("delete from shopcar where shopUserAccount = #{shopUserAccount}")
    void deleteCarByUserAccount(ShopCar shopCar);
}
